package com.hmall.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义全局过滤器（针对所有路由都生效）
 *
 * @Author mr.wu
 * @Date 2025-8-23 11:07
 */
@Slf4j
@Component
public class DemoGlobalFilter implements GlobalFilter, Ordered {


    /**
     * 过滤逻辑：一切的统一过滤处理都在这里写
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("[自定义全局过滤器]我被执行.....");
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0; //数字指的是当前过滤器的执行优先级，值越小优先级越高，越先被执行
    }
}
